package com.yj.suncity.user;

import com.yj.suncity.R;
import com.yj.suncity.utis.ToastUtil;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

public class RegistActivity1 extends Activity implements OnClickListener {
	private Context context;
	private int userType;// 1、个人；2、商户
	private EditText mEdt_user_pwd1, mEdt_user_pwd2;
	private String phone;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_regist1);
		userType = getIntent().getIntExtra("usertype", 0);
		phone = getIntent().getStringExtra("phone");
		context = this;
		findView();
	}

	private void findView() {
		if (userType == 1) {
			((TextView) findViewById(R.id.txt_title_name)).setText("个人注册(2/3)");
		} else if (userType == 2) {
			((TextView) findViewById(R.id.txt_title_name)).setText("商户注册(2/3)");
		}

		mEdt_user_pwd1 = (EditText) findViewById(R.id.edt_user_pwd1);
		mEdt_user_pwd2 = (EditText) findViewById(R.id.edt_user_pwd2);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnHeadBack:
			this.finish();
		case R.id.btn_next:
			String pwd1 = mEdt_user_pwd1.getText().toString().trim();
			String pwd2 = mEdt_user_pwd2.getText().toString().trim();

			if (pwd1.equals("")) {
				ToastUtil.ShowToast(context, "请输入密码！");
				return;
			}
			if (!pwd1.equals(pwd2)) {
				ToastUtil.ShowToast(context, "两次输入密码不一样！");
				return;
			}
			Intent intent = new Intent(this, RegistActivity2.class);
			intent.putExtra("pwd", pwd1);
			intent.putExtra("phone", phone);
			intent.putExtra("usertype", userType);
			startActivityForResult(intent, 1);

		default:
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == 1 && resultCode == 1) {
			setResult(1);
			this.finish();
		}

		super.onActivityResult(requestCode, resultCode, data);
	}

}
